Skip to main content

libobs_simple\sources\linux\sources\pipewire/
camera.rs

1use libobs_simple_macro::obs_object_builder;
2use libobs_wrapper::{
3    data::ObsObjectBuilder,
4    sources::{ObsSourceBuilder, ObsSourceRef},
5};
6
7#[derive(Debug)]
8/// A source for PipeWire camera capture via camera portal.
9///
10/// This source captures video from camera devices through PipeWire's camera portal,
11/// providing secure access to camera devices in sandboxed environments.
12#[obs_object_builder("pipewire-camera-source")]
13pub struct PipeWireCameraSourceBuilder {
14    /// Camera device node (e.g., "/dev/video0")
15    #[obs_property(type_t = "string")]
16    camera_id: String,
17
18    /// Video format (FOURCC as string)
19    #[obs_property(type_t = "string")]
20    video_format: String,
21
22    /// Resolution as "width x height"
23    #[obs_property(type_t = "string")]
24    resolution: String,
25
26    /// Framerate as "num/den"
27    #[obs_property(type_t = "string")]
28    framerate: String,
29}
30
31impl ObsSourceBuilder for PipeWireCameraSourceBuilder {
32    type T = ObsSourceRef;
33
34    fn build(self) -> Result<Self::T, libobs_wrapper::utils::ObsError>
35    where
36        Self: Sized,
37    {
38        let runtime = self.runtime.clone();
39        let info = self.object_build()?;
40
41        let source = ObsSourceRef::new_from_info(info, runtime)?;
42        Ok(source)
43    }
44}
45
46impl PipeWireCameraSourceBuilder {
47    /// Set resolution using width and height values
48    pub fn set_resolution_values(self, width: u32, height: u32) -> Self {
49        self.set_resolution(format!("{}x{}", width, height))
50    }
51
52    /// Set framerate using numerator and denominator
53    pub fn set_framerate_values(self, num: u32, den: u32) -> Self {
54        self.set_framerate(format!("{}/{}", num, den))
55    }
56}